package com.liao.base.base.utils;

/**
 * @author 28580
 * @version 1.0
 * @description: TODO
 * @date 2023/7/23 10:22
 */
import java.util.Map;

public class UserContextHolder {
    private ThreadLocal<Map<String, String>> threadLocal;

    private UserContextHolder() {
        this.threadLocal = new ThreadLocal();
    }

    public static UserContextHolder getInstance() {
        return UserContextHolder.SingletonHolder.sInstance;
    }

    public void setContext(Map<String, String> map) {
        this.threadLocal.set(map);
    }

    public Map<String, String> getContext() {
        return (Map)this.threadLocal.get();
    }

    public void clear() {
        this.threadLocal.remove();
    }

    private static class SingletonHolder {
        private static final UserContextHolder sInstance = new UserContextHolder();

        private SingletonHolder() {
        }
    }
}
